<template>
  <div>
    <div style="width: 660px; margin:20px auto;">
      &emsp;
      <el-select v-model="state" placeholder="请选择状态">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option> </el-select
      >&emsp;

      <el-input
        v-model="iphone"
        style="width: 250px"
        placeholder="请输入账号"
      ></el-input>
      &emsp;

      <el-button plain @click="selectOOW()">&nbsp;查询&nbsp;</el-button>
    </div>
    <el-table :data="resumeOnelist" border>
      <el-table-column prop="iphone" label="账号"></el-table-column>
      <el-table-column prop="paw" label="密码"></el-table-column>
      <el-table-column prop="state" label="状态">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.state"
            :active-value="1"
            :inactive-value="0"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="changestate(scope.row.id,scope.row.state)"
          />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      iphone:'',
      state:'',
      options: [{
          value: '1',
          label: '已启用'
        }, {
          value: '0',
          label: '未启用'
          }, {
          value: '',
          label: '全部'
        }],
      resumeOnelist: [],
    };
  },
  methods: {
    //查询
    selectOOW(){
      var url = this.$store.state.ip + "/admin";
      let param = new URLSearchParams();
      if(this.state != '' && this.iphone != ''){
        url = url+"/selectTo";
        param.append("state", this.state);
        param.append("iphone", this.iphone);
      }else if (this.state == '' && this.iphone == ''){
        this.selectResume();
      }
      else{
        if(this.state != ''){
            url = url+"/bystate";
            param.append("state", this.state);
        }
        else{
          url = url+"/iphone";
          param.append("iphone", this.iphone);
        }
      }
      this.$axios({
        method: "post",
        url: url,
        data: param,
      }).then((res) => {
        console.log(res.data);
        this.resumeOnelist = res.data;
      });
    },
    selectResume() {
      var url = this.$store.state.ip + "/admin/all";
      // 参数
      let param = new URLSearchParams();
      this.$axios({
        method: "post",
        url: url,
        data: param,
      }).then((res) => {
        console.log(res.data);
        this.resumeOnelist = res.data;
      });
    },
    // 改变管理员状态
    changestate: function (id,state) {
      var url = this.$store.state.ip + "/admin/updateState";
      // 参数
      let param = new URLSearchParams();
      param.append("id", id);
      param.append("state", state);
      this.$axios({
        method: "post",
        url: url,
        data: param,
      }).then((res) => {
        console.log(res.data);
      });
    },
  },
  beforeMount() {
    this.selectResume();
  },
};
</script>